package exteditapp;

import java.util.ArrayList;

import exteditapp.state.IState;

/**
 * Subject interface for main module of program.
 * 
 * Part of Observer Software Pattern implementation, which allows register several interfaces for
 * same subject and interface's states will change simultaneously as subject's state changes.
 * This is Subject interface - class, which implements this interface is able to change state
 * of any class, which implements Listener interfaces.
 * @author Arturas Smorgun, arturas@smorgun.lt
 * @version 2009.04.21
 */
public interface ISubject  {

	/**
	 * List of listeners for current subject. It may be graphic representation of Subject's state or
	 * logger or anything else.
	 */
	public ArrayList<IListener> listeners = new ArrayList<IListener>();

	/**
	 * Tries to register new listener to current subject. On success returns true and false otherwise
	 * @param listener new listener, which will be notified on state change
	 * @return true on insert and false if listener already registered
	 */
	public boolean registerListener(IListener listener);
	
	/**
	 * Tries to unregister existing listener from current subject. On success returns true and false otherwise
	 * @param listener listener, which will be removed from notification list
	 * @return true on removal and false if listener don't exist in list
	 */
	public boolean unregisterListener(IListener listener);
	
	/**
	 * Allows to get state of current subject to unregistered listeners
	 * @return current state (can be used not only by unregistered listeners)
	 */
	public abstract IState getState();
	
	/**
	 * Notifies all listeners of current subject about changed state of current subject. 
	 */
	public abstract void notifyListeners();

}
